var app = sm("do_App");
var page = sm("do_Page");
var nf = sm("do_Notification");
var root=ui("$");
var bizzType = require("helper/bizzType");
var openHelper = require("helper/open");
var imHelper = require("helper/im");
var pubUrl = require("url/pub");
var httpSilence = require("helper/httpSilence");
var do_ALayout_detail = ui("do_ALayout_detail");
var label_shopName = ui("label_shopName");
var sendDeliveryType = ui("sendDeliveryType");
var aLayout_sendDeliveryType1 = ui("aLayout_sendDeliveryType1");
var aLayout_sendDeliveryType2 = ui("aLayout_sendDeliveryType2");
var label_sendDeliveryType1 = ui("label_sendDeliveryType1");
var label_sendDeliveryType2 = ui("label_sendDeliveryType2");
var aLayout_concern = ui("aLayout_concern");
var aLayout_resume = ui("aLayout_resume");
root.setMapping({
	"label_shopName.tag":"id",
	"label_shopName.text":"name",	
	"imageView_logo.source":"fullLogo",
	"sendDeliveryType.tag":"sendDeliveryTypeStr2",
	"label_resume.text":"resume",
	"label_userNick.tag":"creatorId",
	"label_userNick.text":"userNick",
	"aLayout_concern.tag":"hasCollect"
});

root.on("dataRefreshed", function(){
	var sendDeliveryTypeStr = sendDeliveryType.tag;
	var array = sendDeliveryTypeStr.split("，");
	if (array.length == 1) {
		label_sendDeliveryType1.text=array[0];
		aLayout_sendDeliveryType2.visible=false;
		label_sendDeliveryType2.visible=false;
	} else {
		label_sendDeliveryType1.text=array[0];
		label_sendDeliveryType2.text=array[1];
	}
	if (aLayout_concern.tag==true || aLayout_concern.tag == 'true') {
		hasCollectYes();
	} else {
		hasCollectNo();
	}
});

do_ALayout_detail.on("touch",'' ,300,function(data, e) {
	openHelper.open("source://view/qshop/detail/detail.ui",{shopId:label_shopName.tag});
});
aLayout_concern.on("touch",'' ,300,function(data, e) {
	var addParams = {
		bizzId : label_shopName.tag,
		bizzType : bizzType.Level2.QSHOP_SHOP
	};
	if (aLayout_concern.tag == 'true') {
		httpSilence.post(pubUrl.url.concern.doCancle, addParams, function(data) {
			hasCollectNo();
		});
	} else {
		httpSilence.post(pubUrl.url.concern.doAdd, addParams, function(data) {
			hasCollectYes();
		});
	}
});

//与店主聊天
ui("do_ALayout_chatIM").on("touch",'' ,300,function(data, e) {
	var shopOwnerId = ui("label_userNick").tag;
	imHelper.toChat(shopOwnerId);
});

aLayout_resume.on("touch",'' ,300,function(data, e) {
	openHelper.open("source://view/qshop/detail/detail.ui",{shopId:label_shopName.tag});
});

function hasCollectYes(){
	aLayout_concern.border = 'fe7e0aFF,1,4';
	ui("do_ImageView_5").source = 'source://image/community/star_on.png';
	ui("do_Label_35").fontColor = 'FE7E0AFF';
	aLayout_concern.tag = 'true';
}
function hasCollectNo(){
	aLayout_concern.border = '949EAAFF,1,4';
	ui("do_ImageView_5").source = 'source://image/community/star.png';
	ui("do_Label_35").fontColor = '949EAAFF';
	aLayout_concern.tag = 'false';
}
